package es.ats.codington.festival.utils;

import java.sql.*;

/**
 * The Class FERSDataConnection.
 */
public class FERSDataConnection {
	
	/** The con. */
	static Connection con;

	//	This source code tries to establish a connection to a MySQL server
	//	and displays a message concerning the error if connection fails
	
	//Following method creates a connection and returns it
	/** The address. */
	private static String address = "src/es/ats/codington/festival/utils/ConectionJson.json";
	
	/**
	 * Gets the connection.
	 *
	 * @return the connection
	 */
	public static Connection getConnection() {
		//JSONQuery reader = new JSONQuery(address);	
		try {
			String url = "jdbc:mysql://localhost:3306/codington5cs";
			String user = "root";
			String pass = "abcd1234";
			String driver = "com.mysql.jdbc.Driver";
			
			//Loading the driver
			Class.forName(driver);//.newInstance();
			
			//Obtaining a connection using DriverManager class
			con = DriverManager.getConnection(url, user, pass);
	
		//	System.out.println(driver+ "/" +url + "/" + user +"/"+pass);
						
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
		return con;
	}
	
	// Closing connection
	/**
	 * Close connection.
	 *
	 * @throws SQLException the SQL exception
	 */
	public static void closeConnection() throws SQLException {
			con.close();
		}
}
